<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>异步请求测试</h1>
<div>
    <input type="text" v-model="info">
    <input type="button" value="异步Get请求" @click="f1()">
    <input type="button"value="异步Post请求" @click="f2()">

    <a href="/bmi.html">身体质量指数测试</a>
    <a href="/reg.html">注册</a>
    <a href="/login.html">登录</a>
</div>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
<script>
  let v = new Vue({
    el:"body>div",
    data:{
        info:""
    },
    methods:{
      f1(){
         //发出异步的Get请求   response代表响应,里面装着服务器响应的数据
          axios.get("/helloAxios?info="+v.info).then(function (response){
              //服务器成功响应后,会执行此处代码
              alert(response.data)//代表服务器响应的数据
          })
      },
        f2(){
          //通过js中的自定义对象将多个参数封装到一起
            let user = {username:"姜桑",password:"452",nick:"姜桑"}
          //发出异步的Post请求
            axios.post("/postAxios",user).then(function (response){
                //弹出服务器响应的数据
                alert(response.data);
            })
        }
    }
  })
</script>
</body>
</html>